# update reqs doc_id if is null
class ChangeReqDocId < ActiveRecord::Migration
  
  def self.get_doc_id(p_id)
    return @h[p_id] if @h[p_id]
    @h[p_id] = ReqDoc.find(:first, :conditions=>["project_id=?",p_id]).id
    @h[p_id] = ReqDoc.create(:project_id=>p_id, :title=>"BRD", :descr=>"Business Requirement Dossier").id if not @h[p_id]
    @h[p_id]
  end
  
  def self.up
    @h = Hash.new
    req = Req.find(:all, :conditions=>"doc_id is null")
    req.each { |r|
      r.doc_id = self.get_doc_id(r.project_id)
      r.save
      }
  end

  def self.down
  end
end

